package db

import "errors"

type User struct {
	ID     int64  `xorm:"'id' BIGINT(20) NOT NULL PRIMIARY KEY AUTO_INCREMENT comment('主键')"`
	Uname  string `xorm:"'username' VARCHAR(32) NOT NULL comment('用户名')"`
	Passwd string `xorm:"'password' VARCHAR(128) NOT NULL comment('密码')"`
}

func (d *User) TableName() string {
	return "users"
}

func (d *User) Login(uname, passwd string) (*User, error) {

	var user User

	//链接db 测试 打开注释
	//has, err := DB.Table(d).
	//	Where("username=?", uname).
	//	Where("password=?", passwd).
	//	Get(&user)

	//链接db 测试 删除此行
	has, err := true, errors.New("test")

	if !has {
		return nil, err
	}

	return &user, err
}
